class User {
    constructor(name, interests) {
        this.name = name;
        this.interests = interests;
    }

    greeting() {
        console.log('Hi, I\'m ' + this.name + '.');
    }

    get interestCount() {
        return this.interests ? this.interests.length : 0;
    }
}

class TeamMember extends User {
    constructor(name, interests) {
        super(name, interests);
        this._tasks = [];
        this._welcomeText = 'Welcome to the team!';
    }

    //override
    greeting() {
        console.log('I\' m ' + this.name + '. ' + this._welcomeText);
    }

    //new
    work() {
        console.log('I\' m working on ' + this._tasks.length + ' tasks.')
    }

    set tasks(tasks) {
        let acceptedTasks = [];
        if (tasks.length > TeamMember.maxTaskCapacity()) {
            acceptedTasks = tasks.slice(0, TeamMember.maxTaskCapacity());
            console.log('It\'s over max capacity. Can only take two.');
        } else {
            acceptedTasks = tasks;
        }
        this._tasks = this._tasks.concat(acceptedTasks);
    }

    //static 方法
    static maxTaskCapacity() {
        return 2;
    }
}

let advice =  'Stay hungry. Stay foolish.'; 

let advisor = {
    __proto__: new TeamMember('Adam', ['Consulting']),
    advice,            //相当于advice: advice,
    greeting() {
        super.greeting();
        console.log(advice);
    },
    [advice.split('.')[0]]: 'Always learn more'  //'Stay hungry': 'Always learn more'
}

//实质
console.log(TeamMember.prototype.isPrototypeOf(advisor));  // true 
console.log(advisor instanceof TeamMember);                // true

advisor.greeting();
console.log('-------------')
console.log(advisor['Stay hungry']);
